
package com.csc440.team2.activity;

import java.io.File;


import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Display;
import android.widget.RelativeLayout.LayoutParams;


import com.csc440.team2.SmilConstants;
import com.csc440.team2.layout.MessageLayout;
import com.csc440.team2.layout.MessageLayoutPlayer;
import com.csc440.team2.smil.SMILMessage;


/**
 * Main class for the SMIL Player. This class loads the MessageLayout that
 * serves as the container for playing the SMIL message.
 * 
 * @author Alex Povkov, Santiago Jamriska, Brad Gardner
 * @see MessageLayout
 * @see MessageLayoutPlayer
 */
public class SMILPlayer extends Activity
{
    private SMILMessage message;
    private MessageLayoutPlayer layout;


    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        try
        {
            File sdRoot = Environment.getExternalStorageDirectory();

            if (sdRoot.canRead())
            {
                // pull the message from the bundle
                Bundle bundle = getIntent().getExtras();
                if (bundle != null)
                {
                    message = (SMILMessage) bundle.getSerializable(SmilConstants.MESSAGE);
                    buildLayout();
                }
            }
        }
        catch (Exception e)
        {
            Log.e("Exception", "error occurred while creating xml file", e);
        }
    }


    /**
     * Builds the primary MessageLayout
     */
    public void buildLayout()
    {
        Display display = getWindowManager().getDefaultDisplay();
        LayoutParams layoutParams = new LayoutParams(display.getWidth(), display.getHeight());

        layout = new MessageLayoutPlayer(this, this);
        layout.setLayoutParams(layoutParams);
        setContentView(layout);

        layout.buildLayout(message);
    }


    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onPause()
     */
    @Override
    protected void onPause()
    {
        super.onPause();
    }

}
